//
//  SAConsultationWechatVC.m
//  saasRetail
//
//  Created by mac on 2023/9/10.
//

#import "SAConsultationWechatVC.h"

@interface SAConsultationWechatVC ()

@property (nonatomic, strong) UIImageView *imageV;

@end

@implementation SAConsultationWechatVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - event
-(void)clickedSaveBtn {
    [self loadImageFinished:self.imageV.image];
}

- (void)loadImageFinished:(UIImage *)image
{
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
}
 
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error == nil) {
        [Prompt popPromptViewWithMsg:@"图片保存成功，请在相册中查看！" duration:3];
    }else {
        [Prompt popPromptViewWithMsg:@"图片保存失败" duration:3];
    }
//    NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);
}

#pragma mark - initUI
-(void)initUI {
    
    [self setNavigationItemBackBBIAndTitle:@"客服微信"];
    self.view.backgroundColor = kLineColor;
    [self setBgImage:nil];
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth - kScaleNum(200))/2, kScaleNum(StatusHeight + 50), kScaleNum(200), kScaleNum(200))];
    [imageV sd_setImageWithURL:[NSURL URLWithString:@"http://saas-images.fuyungroup.com/saas-test/238368f5-4646-11ee-bfc9-00163e1470b7.png"]];
    imageV.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:imageV];
    self.imageV = imageV;
    
    UILabel *tipLab = [[UILabel alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight + 250), kScreenWidth, kScaleNum(60))];
    tipLab.textColor = kBlackColor;
    tipLab.font = kFont(13);
    tipLab.text = @"保存客服微信二维码到相册，前往\n微信扫一扫识别添加";
    tipLab.textAlignment = NSTextAlignmentCenter;
    tipLab.numberOfLines = 0;
    [self.view addSubview:tipLab];
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake((kScreenWidth - kScaleNum(250))/2, kScaleNum(StatusHeight + 310), kScaleNum(250), kScaleNum(40));
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn setTitleColor:kBuleColor forState:UIControlStateNormal];
    saveBtn.titleLabel.font = kFont(16);
    [saveBtn addTarget:self action:@selector(clickedSaveBtn) forControlEvents:UIControlEventTouchUpInside];
    saveBtn.backgroundColor = [UIColor whiteColor];
    saveBtn.layer.cornerRadius = kScaleNum(5);
    saveBtn.layer.masksToBounds = YES;
    [self.view addSubview:saveBtn];
    
}

@end
